package com.ssr.ld.action.admin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssr.ld.action.BaseAction;
import com.ssr.ld.bean.User;
import com.ssr.ld.service.UserService;
import com.ssr.ld.utils.DateUtils;
import com.ssr.ld.vo.ResultVo;
@Controller
@RequestMapping("/admin/user/")
public class UserAction extends BaseAction{
	@Autowired
	private UserService userService;
	
	@RequestMapping("/list")
	public String index(HttpServletRequest request,
			HttpServletResponse response){
		request.setAttribute("startDate", DateUtils.getCurrentDay("yyyy-MM-dd",-5));
		request.setAttribute("endDate",DateUtils.getCurrentDay("yyyy-MM-dd"));
		return "/admin/user/list";
	}
	
	@RequestMapping("/load")
	@ResponseBody
	public ResultVo load(HttpServletRequest request, HttpServletResponse response, User user){
		if(user.getBeginTime()==null){
			user.setBeginTime(DateUtils.getCurrentDay("yyyy-MM-dd HH:mm:ss",-5));
			user.setEndTime(DateUtils.getCurrentDay("yyyy-MM-dd HH:mm:ss"));
		}
		List<User> list=userService.queryByPage(user);
		long count=0;
		if(!list.isEmpty()){
			count=userService.count(user);
		}
		return  ResultVo.success(list, count);
	}
		
}
